package com.mao.Interface;

public class ClassDataInterImpl2 implements ClassDataInter {
    Student[] students;
    public ClassDataInterImpl2(Student [] students)
    {
        this.students = students;
    }
    @Override
    public void printAllStudentInfos(){
        System.out.println("全班学生信息如下：");
        int maleCount = 0;
        for (int i = 0; i < students.length; i++)
        {
            Student s = students[i];
            if(s.getSex() == '男')
            {
                maleCount++;
            }
            System.out.println(s.getName()+" "+s.getSex()+" "+s.getScore());
        }
        System.out.println("男学生人数为："+maleCount);
        System.out.println("女学生人数为："+(students.length-maleCount));

    }
    //去掉最高分和最低分后，计算平均分
    @Override
    public void printAverageScore(){
        System.out.println("去掉最高分和最低分后，平均分：");
        double sum = 0.0;
        double max = students[0].getScore();
        double min = students[0].getScore();
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            if (s.getScore() > max) {
                max = s.getScore();
            }
            if (s.getScore() < min) {
                min = s.getScore();
            }
            sum += s.getScore();
        }
        System.out.println((sum-max-min)/(students.length-2));
        System.out.println("最高分："+max);
        System.out.println("最低分："+min);
        System.out.println("总分："+sum);
    }
}
